package org.example.config;

import org.example.storage.GenericStorage;

/**
 * 存储自动配置 - 单例模式
 */
public class StorageAutoConfiguration {

    private final StorageProperties properties;
    private static StorageAutoConfiguration instance;

    private StorageAutoConfiguration() {
        this.properties = new StorageProperties();
    }

    private StorageAutoConfiguration(StorageProperties properties) {
        this.properties = properties;
    }

    /**
     * 获取单例实例
     */
    public static synchronized StorageAutoConfiguration getInstance() {
        if (instance == null) {
            instance = new StorageAutoConfiguration();
        }
        return instance;
    }

    /**
     * 获取带自定义配置的单例实例
     */
    public static synchronized StorageAutoConfiguration getInstance(StorageProperties properties) {
        if (instance == null) {
            instance = new StorageAutoConfiguration(properties);
        }
        return instance;
    }

    /**
     * 创建通用存储
     */
    public <K, V> GenericStorage<K, V> createGenericStorage() {
        return new GenericStorage<>();
    }


    public StorageProperties getStorageProperties() {
        return properties;
    }

    /**
     * 关闭所有存储资源
     */
    public void shutdown() {
        // 这里可以添加需要关闭的资源
        instance = null;
    }
}